package final2107.day13;

import java.lang.reflect.Method;

public class ReflectDemo01 {
    public static void main(String[] args) throws NoSuchMethodException {
        //获取当前类的Class对象
        Class cls = ReflectDemo01.class;
        //运行期获取所有方法并输出
//        Method[] methods = cls.getMethods();
        Method[] methods = cls.getDeclaredMethods();
        //只获取本类中的所有方法
//        for (Method method:methods) {
//            System.out.println(method.getName());
//        }

        //获取demo方法
//        Method method = cls.getDeclaredMethod("demo",int.class,String.class,int.class);
//        System.out.println(method);

        //无法获取私有的方法
//        Method method = cls.getMethod("demo", int.class, String.class, int.class);
//        System.out.println(method);

        //获取test方法
//        Method method1 = cls.getDeclaredMethod("test");
        Method method1 = cls.getMethod("test");
        System.out.println(method1);

    }

    public void test(){}
    private int demo(int i,String s,int m){
        return 1;
    }
    private void test2(){}
}
